import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JFrame;



public class Main {
  public static void main(String[] a) {
	  //  looping Bezier curve 
	  //float[] control_x = {  0.0f, 200.0f,200.0f,-100.0f,200.0f,256.0f};
	  //float[] control_y = {200.0f, 200.0f,-250.0f,200.0f,300.0f, 56.0f};
	  
	  float[] control_x = {  0.0f, 100.0f,150.0f,200.0f,230.0f,256.0f};
	  float[] control_y = {200.0f, 200.0f,-250.0f,200.0f,300.0f,156.0f};
	  Color myC = new Color(255,0,0,255);
	 
	MyCanvas graph = new MyCanvas();
	graph.setXYControlPoints(control_x, control_y);
	graph.setColor(myC);
		
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setBounds(30, 30, 400, 400);
    window.getContentPane().add(graph);
    window.setVisible(true);
  } 
  
}

class MyCanvas extends JComponent {

	private float[] x1;
	private float[] y1;
	private Color c; //black by default.
	
	// you should be able to set these values from the calling class or main.
	// but I still need to add the getters and setters.
	private int offset_x = 10;
	private int offset_y = 266; // offset_x + maxSize 
	
	private int maxSize = 256; //size of the "grid" we are drawing on.
	
	
	  public void paint(Graphics g) {
	    Casteljau cJau = new Casteljau(x1,y1,x1.length);
	    float[] p = {0.0f,0.0f};
	    g.setColor(c);
		for(int i = 0; i< maxSize; i++ ){
			p = cJau.getXYvalues((float)i/(float)maxSize); // this must be a float between [0.0f,1.0f]
	
			g.drawRect ( (int)p[0] +offset_x , (int)-p[1]+ offset_y, 1, 1); 
		}
	  }
	  
	  public void setXYControlPoints(float[] x1,float[] y1){
		  this.x1 = x1;
		  this.y1 = y1;
	  }
	  
	  public void setColor(Color c){
		  this.c = c;
	  }
	  
	  
	  
}


